1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
enum MovementType {
6     NONE =
0,
7     KING =
1,
8     PAWN =
2,
9     ROOK =
3,
10     BISHOP =
4,
11     QUEEN =
5,
12     KNIGHT =
6,
13     CIRCLE =
7,
14     CROSS =
8,
15 }

16
17 public
abstract class Movement : ScriptableObject {
18
19     
protected GCPlayer player;
20     
protected Piece piece;
21     
protected bool moved = false;
22
23     
public event ComputeBound BoundComputations;
24
25     
public Movement(GCPlayer player, Piece piece) {
26         
this.player = player;
27         
this.piece = piece;
28         BoundComputations += ClearPossibles;
29     }
30
31     
void DisableCalculation() {
32         BoundComputations =
null;
33     }
34
35     
void OnDisable() {
36         DisableCalculation();
37     }
38
39     
public virtual void ComputeBound() {}
40
41     
public bool IsTurn() {
42         
if (player == GameManager.Instance.CurrentPlayer) {
43             
return true;
44         }
45
46         
return false;
47     }
48
49     
public void ClearPossibles() {
50         piece.ClearPossibleEats();
51         piece.ClearPossibleMoves();
52     }
53
54     
public bool ComputeMovePiece(Node toCheckNode) {
55         
if (toCheckNode == null) return false;
56         
if (toCheckNode.EmptySpace) {
57             piece.AddPossibleMoves(toCheckNode);
58             
return true;
59         }
60
61         
return false;
62     }
63
64     
public bool ComputeEatPiece(Node toCheckNode) {
65         
if (toCheckNode == null) return false;
66         
if (!toCheckNode.EmptySpace && Rules.IsEnemy(piece, toCheckNode.Piece)) {
67             AddToCheckOrEat(toCheckNode);
68             
return true;
69         }
70
71         
return false;
72     }
73
74     
public bool ComputeMoveOrEatPiece(Node toCheckNode) {
75         
if (toCheckNode == null) return false;
76         
if (toCheckNode.EmptySpace) {
77             piece.AddPossibleMoves(toCheckNode);
78             
return true;
79         }
else if (Rules.IsEnemy(piece, toCheckNode.Piece)) {
80             AddToCheckOrEat(toCheckNode);
81             
return true;
82         }
83
84         
return false;
85     }
86
87     
public virtual void Compute() {
88         
if (piece == null || piece.Node == null) return;
89         BoundComputations();
90     }
91
92     
//returns true if met an ally or enemy, this is for square and triangle, to cause a block
93     
public bool ComputeMoveOrEatPieceEnemyAlly(Node toCheckNode) {
94         
if (toCheckNode == null) return false;
95         
if (toCheckNode.EmptySpace) {
96             piece.AddPossibleMoves(toCheckNode);
97         }
else if (Rules.IsEnemy(piece, toCheckNode.Piece)) {
98             AddToCheckOrEat(toCheckNode);
99             
if (toCheckNode != toCheckNode.Piece.Node) {
100                 
return false;
101             }
else {
102                 
return true;
103             }
104         }
else {
105             
return true;
106         }
107
108         
return false;
109     }
110
111     
private void AddToCheckOrEat(Node toCheckNode) {
112         
if (Rules.CheckKing(player, piece.Node, toCheckNode)) {
113             
//playerPiece.Check = toCheckPiece;
114         }
else {
115             piece.AddPossibleEats(toCheckNode);
116         }
117     }
118
119     
public bool IsMoved() {
120         
return moved;
121     }
122
123     
public virtual void Moved() {
124         
if (!moved) {
125             moved =
true;
126         }
127
128         Debug.Log(
"MOVED: " + moved);
129     }
130 }


returns true if met an ally or enemy, this is for square and triangle, to cause a block

playerPiece.Check = toCheckPiece;



Gõ tìm kiếm nhanh...